<script setup>
import { ref } from "vue";

//定义数据类型
const PWDData = ref({
  old_pwd: "",
  new_pwd: "",
  re_pwd: "",
  id: "",
});

import { userPasswordUpdateService } from "@/api/user.js";
import { useTokenStore } from "@/stores/token.js";
import { useRouter } from "vue-router";
import useUserInfoStore from "@/stores/userInfo.js";
const userInfoStore = useUserInfoStore();
const router = useRouter();
const tokenStore = useTokenStore();
import { ElMessage } from "element-plus";
//修改密码
const showDialog = async () => {
  //调用接口
  let result = await userPasswordUpdateService(PWDData.value);
  ElMessage.success(result.msg ? result.msg : "修改成功、请重新登录");

  //清空pinia中存储的token以及个人信息
  tokenStore.removeToken();
  userInfoStore.removeInfo();
  //跳转页面
  router.push("/login");
};
</script>
<template>
  <div class="box">
    <el-card class="page-container">
      <template #header>
        <div class="header">
          <span>修改密码</span>
        </div>
      </template>
      <el-row>
        <el-col :span="12">
          <el-form :model="PWDData" label-width="100px" size="large">
            <el-form-item label="旧密码">
              <el-input v-model="PWDData.old_pwd"></el-input>
            </el-form-item>
            <el-form-item label="新密码">
              <el-input v-model="PWDData.new_pwd"></el-input>
            </el-form-item>
            <el-form-item label="确认密码">
              <el-input v-model="PWDData.re_pwd"></el-input>
            </el-form-item>
            <el-form-item>
              <el-button type="primary" @click="showDialog()"
                >提交修改</el-button
              >
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
    </el-card>
  </div>
</template>

<style lang="scss" scoped>
.box {
  -webkit-user-select: none;

  -moz-user-select: none;

  -ms-user-select: none;

  user-select: none;
}
</style>
